/**
 * @ClassName LC485
 * @Author ykx
 * @Date 2024/6/23 16:17
 * @Version 1.0
 */
public class LC485 {
    public static void main(String[] args) {
        LC485 lc485 = new LC485();
        System.out.println(lc485.findMaxConsecutiveOnes(new int[]{1}));
    }

    public int findMaxConsecutiveOnes(int[] nums) {
        // 记录第一个0的位置
        int temp = 0;
        boolean isExist0 = false;
        for (int i = 0; i < nums.length; i++) {
            if (nums[i] == 0) {
                temp = i;
                isExist0 = true;
                break;
            }
        }

        // 假设这是最长的连续1的个数
        if (isExist0) {
            int result = temp;
            for (int i = temp + 1; i < nums.length; i++) {
                if (nums[i] == 0) {
                    result = Math.max(result, i - temp - 1);
                    temp = i;
                }
                if (i == nums.length - 1) {
                    result = Math.max(result, i - temp);
                }

            }
            return result;
        } else {
            return nums.length;
        }


    }
}
